package br.com.batista.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.classic.Session;

@SuppressWarnings("deprecation")
public class BuscaProdutos {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Session session = teste();
		
		Query sql = session.createQuery("select p from Produto as p where p.preco > :paramPreco");
		sql.setParameter("paramPreco", 10.0);
		
		List<Produto> lista = sql.list();
		
		for (Produto p : lista) {
			System.out.println(p.getNome());
		}
		session.close();
	}

	private static Session teste() {
		AnnotationConfiguration cf = new AnnotationConfiguration();
		cf.addAnnotatedClass(Produto.class);
		
		SessionFactory sf = cf.buildSessionFactory();
		Session session = sf.openSession();
		return session;
	}

}
